
using System.Globalization;
using Mistral;

namespace Conditions.String
{
	public struct Condition_String_Equals : ICondition<string>
	{
		private string m_name;
		private bool m_bIgnoreCase;

		public Condition_String_Equals( string name )
			: this( name, true )
		{
		}

		public Condition_String_Equals( string name, bool bIgnoreCase )
		{
			m_bIgnoreCase = bIgnoreCase;
			m_name = name;
		}

		#region ICondition<string> Members

		public bool Matches( string value )
		{
			return ( string.Compare( value, m_name, m_bIgnoreCase ) == 0 );
		}

		#endregion
	}

	public struct Condition_String_StartsWith : ICondition<string>
	{
		string m_partName;
		bool m_bIgnoreCase;
		CultureInfo m_culture;

		public Condition_String_StartsWith( string partName ) :
			this( partName, true, CultureInfo.CurrentCulture )
		{
		}

		public Condition_String_StartsWith( string partName, bool bIgnoreCase ):
			this( partName, bIgnoreCase, CultureInfo.CurrentCulture )
		{
		}

		public Condition_String_StartsWith( string partName, bool bIgnoreCase, CultureInfo culture )
		{
			m_bIgnoreCase = bIgnoreCase;
			m_partName = partName;
			m_culture = culture;
		}

		#region ICondition<string> Members

		public bool Matches( string value )
		{
			return value.StartsWith( m_partName, m_bIgnoreCase, m_culture );
		}

		#endregion
	}

	public struct Condition_String_EndsWith : ICondition<string>
	{
		string m_partName;
		bool m_bIgnoreCase;
		CultureInfo m_culture;

		public Condition_String_EndsWith( string partName ) :
			this( partName, true, CultureInfo.CurrentCulture )
		{
		}

		public Condition_String_EndsWith( string partName, bool bIgnoreCase ):
			this( partName, bIgnoreCase, CultureInfo.CurrentCulture )
		{
		}

		public Condition_String_EndsWith( string partName, bool bIgnoreCase, CultureInfo culture )
		{
			m_bIgnoreCase = bIgnoreCase;
			m_partName = partName;
			m_culture = culture;
		}

		#region ICondition<string> Members

		public bool Matches( string value )
		{
			return value.EndsWith( m_partName, m_bIgnoreCase, m_culture );
		}

		#endregion
	}

	public struct Condition_String_Contains : ICondition<string>
	{
		string m_partName;
		bool m_bIgnoreCase;

		public Condition_String_Contains( string partName ) :
			this( partName, true )
		{
		}

		public Condition_String_Contains( string PartName, bool bIgnoreCase )
		{
			m_bIgnoreCase = bIgnoreCase;
			m_partName = bIgnoreCase? PartName.ToLower( ) : PartName;
		}

		#region ICondition<string> Members

		public bool Matches( string value )
		{
			string item = m_bIgnoreCase ? value.ToLower() : value;
			return ( item.IndexOf( m_partName ) >= 0 );
		}

		#endregion
	}
}
